package javaCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by lxy_920912 on 2017/1/11.
 */
public class LeetCode257 {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> resultList = new ArrayList<>();
        if(root == null){
            return resultList;
        }
        String path = new String(root.val+"");
        findPath(root.left,path,resultList);
        findPath(root.right,path,resultList);
        return resultList;
    }
    public void findPath(TreeNode root,String path,List<String> resultList){
        if(root != null){
            String newPath = path+"->"+root.val;
            if(root.left == null && root.right == null){
                resultList.add(path);
            }
            findPath(root.left,newPath,resultList);
            findPath(root.right,newPath,resultList);
        }
    }
}
